package com.starrin.trashtalk.util;


import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
import org.apache.log4j.Logger;


/**
 * Created by larsstarrin on 12/10/14.
 */
public class EmailSender {
    private static final Logger logger = Logger.getLogger(EmailSender.class);

    public void sendEmail(String to, String subject, String messageBody) {
        try {
            HtmlEmail email = new HtmlEmail();
            email.setHostName("smtp.playtennis.se");
            email.setSmtpPort(587);
            email.setAuthenticator(new DefaultAuthenticator("info@playtennis.se", "lap1nkulta"));
            email.setSSLOnConnect(false);
            email.setFrom("info@playtennis.se");
            email.setSubject(subject);
            email.setHtmlMsg(messageBody);
            // set the alternative message
            //email.setTextMsg("This is a link: http://pushpalankajaya.blogspot.com");
            email.addTo(to);
            email.send();
        } catch (EmailException e) {
            logger.error("Could not send email to " + to, e);
        }
    }

}
